package com.centling.smartSealForPhone.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.bean.DeviceInfoBean;
import com.centling.smartSealForPhone.constants.UrlConstants;
import com.centling.smartSealForPhone.utils.OkHttpUtil;
import com.centling.smartSealForPhone.utils.ShowToast;
import com.google.gson.Gson;

/**
 * 设备信息查看
 */
public class DeviceInfoActivity extends TitleBarActivity {
    private TextView tvSn;
    private TextView tvRegisterTime;//注册时间
    private TextView tvSealName;//印章名
    private TextView tvCompanyName; //公司名

    private DeviceInfoBean data;

    private static String bytesToHexString(byte[] src) {
        StringBuilder stringBuilder = new StringBuilder();
        if (src == null || src.length <= 0) {
            return null;
        }
        for (int i = 0; i < src.length; i++) {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv);
        }
        return stringBuilder.toString();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_info);
        setTitleBarText("设备信息");
        initView();
        setData();
    }

    private void initView() {
        tvSn = (TextView) findViewById(R.id.tv_id);
        tvRegisterTime = (TextView) findViewById(R.id.tv_register_time);
        tvSealName = (TextView) findViewById(R.id.tv_seal_name);
        tvCompanyName = (TextView) findViewById(R.id.tv_company_name);
    }

    private void setData() {
        getEnqueue(UrlConstants.GET_DEVICE_INFO, new OkHttpUtil.NetCallBack() {
            @Override
            public void onSucceed(String json) {
                data = new Gson().fromJson(json, DeviceInfoBean.class);
                tvSn.setText(data.getAscSn());
                tvRegisterTime.setText(data.getCreatedDate());
                tvSealName.setText(data.getSealName());
                tvCompanyName.setText(data.getSealOrg());
            }

            @Override
            public void onFailed(String reason) {
                ShowToast.shortTime(reason);
            }
        });

    }
}


